package resource
{
	import flash.display.*;
	import flash.utils.Dictionary;
	
	import utils.StringUtil;
	
	
	//预先加载的资源
	public class LoadResource
	{
		public static var imgResource:*;//预加载的图
		public static var boneList:Dictionary = new Dictionary();//预先加载的角色骨骼  后续加载的怪物骨骼也存放在这里
		public static var loadedAction:Dictionary = new Dictionary();//加载的角色动作和法术动作特效配置
		public static var smallMap:Object;//所有的小地图
		
		public static function getSmallMap(url:String):Bitmap{//small_map_1.gif
			if (url != null && url != null && smallMap != null && smallMap.dictionary[url] != null){
				var bitmapData:BitmapData = new smallMap.dictionary[url](1,1);
				return new Bitmap(bitmapData);
			}
			return new Bitmap();
		}
		
		//---------------------骨骼-----------------------
		//加载完成初始骨骼
		public static function initBone(lib:Object,id:String):void
		{
			if(lib == null || lib.dictionary == null || boneList[id] != null)
			{
				return;
			}
			var boneObjs:Array = [];
			for(var key:String in lib.dictionary)
			{
				try
				{
					boneObjs[key] = new Bitmap(new lib.dictionary[key](0,0), "auto", true);
				}
				catch(e:Error)
				{
					
				}
			}
			
			boneList[id]=  boneObjs;
		}
		/**
		 * 取整套骨骼 
		 * @param boneUrl
		 * @return 
		 * 
		 */
		public static function getBone(boneUrl:String):Array
		{
			var boneObjs:Array = boneList[boneUrl];
			
			return boneObjs;
		}
		/**
		 * 取单个骨骼 
		 * @param boneUrl 骨骼库id
		 * @param boneType 骨骼类型 名字 比如 hair1 hair2 等
		 * @return 
		 * 
		 */		
		public static function getBoneByType(boneUrl:String,boneType:String):*
		{
			var boneObjs:Array = boneList[boneUrl];
			if(null != boneObjs && null != boneObjs[boneType])
			{
				return boneObjs[boneType];
			}
			
			return new DisplayObject();
		}
		
		//---------------------界面图-----------------------
		
		public static function getLocalImage(url:String):Bitmap
		{
			var bitmapData:BitmapData = getLocalBitmapData(url);
			if(bitmapData != null){	
				return new Bitmap(bitmapData as BitmapData);
			}else{
				trace("无图",url);
				return null;
			}
		}
		
		public static function getLocalBitmapXY(url:String,x:int = 0,y:int = 0):Bitmap
		{
			var bitmap:Bitmap = getLocalImage(url);
			if( bitmap!=null ){
				bitmap.x = x;
				bitmap.y = y;
			}
			return bitmap;
		}
		
		public static  function getLocalBitmapData(url:String):BitmapData{
			if (url != null && url != null && imgResource != null && imgResource.dictionary[url] != null){
				var bitmapData:BitmapData = new imgResource.dictionary[url](1,1);
				return bitmapData.clone();
			}
			return null;
		}
	}
}